#ifndef DATEOFFSETCALCULATOR_H
#define DATEOFFSETCALCULATOR_H

#include <iostream>
#include <ctime>
#include <conio.h>

using namespace std;

class fuction5 {
public:
    void Calculate() {
        int offset;
        cout << "请输入距离今天的天数（正整数）: ";
        cin >> offset;

        // 获取当前时间
        time_t now = time(NULL);
        tm* today_tm = localtime(&now);

        // 显示今天
        cout << "\n今天是："
             << today_tm->tm_year + 1900 << "年"
             << today_tm->tm_mon + 1 << "月"
             << today_tm->tm_mday << "日"
             << "（星期" << WeekdayName(today_tm->tm_wday) << "）" << endl;
        const int x= 86400;
        time_t early_time = now - offset * x;
        tm* early_tm = localtime(&early_time);
        cout << "\n早 " << offset << " 天的日期为："
             << early_tm->tm_year + 1900 << "年"
             << early_tm->tm_mon + 1 << "月"
             << early_tm->tm_mday << "日"
             << " 星期" << WeekdayName(early_tm->tm_wday) << endl;
        time_t later_time = now + offset * x;
        tm* later_tm = localtime(&later_time);
        cout << "晚 " << offset << " 天的日期为："
             << later_tm->tm_year + 1900 << "年"
             << later_tm->tm_mon + 1 << "月"
             << later_tm->tm_mday << "日"
             << " 星期" << WeekdayName(later_tm->tm_wday) << endl;
        cout << "\n按任意键返回菜单..." << endl;
        _getch();
    }
private:
    const char* WeekdayName(int wday) {
        static const char* names[7] = {
            "日", "一", "二", "三", "四", "五", "六"
        };
        return (wday >= 0 && wday < 7) ? names[wday] : "?";
    }
};
#endif 
